<template>
  <uni-page-wrapper>
    <uni-page-body>
      <!-- 第一次的修改 -->
      <uni-popup ref="popup" type="dialog">
        <uni-popup-dialog
          type="info"
          mode="input"
          :title="popupTitle"
          :placeholder="popupPlaceholder"
          :before-close="true"
          @close="close"
          @confirm="confirm"
        >
          <input type="text" />
        </uni-popup-dialog>
      </uni-popup>
      <!-- 第二次的提醒 -->
      <uni-popup ref="popup2" type="dialog">
        <uni-popup-dialog
          type="info"
          :title="popup2Title"
          :before-close="true"
          @close="close2"
          @confirm="confirm2"
        >
          <input type="text" />
        </uni-popup-dialog>
      </uni-popup>
      <uni-view class="paddingView">
        <uni-view class="header">
          <uni-view class="top">
            <uni-image class="left">
              <div
                style="
                  background-image: url('/static/img/avatar.42fc3f14.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/img/avatar.42fc3f14.png" />
            </uni-image>
            <uni-view class="right">
              <uni-view class="t">
                <uni-view class="l">{{ username }}</uni-view>
                <uni-view class="r">{{ $t("me.LV") }}{{ level }}</uni-view>
				<uni-view class="l" style="margin-left: 10px;">{{ $t("me.Credits") }}</uni-view>
				<uni-view class="r">{{ score }}</uni-view>
              </uni-view>
              <uni-view class="b">{{ $t("me.Choose Amazon,Choose Wealth") }}</uni-view>
            </uni-view>
          </uni-view>
          <uni-view class="moneyBox">
            <uni-view class="left">
              <uni-view class="t">{{ $t("me.Balance") }}</uni-view>
              <uni-view class="b">{{ balance }}</uni-view>
            </uni-view>
            <uni-view class="right">
              <uni-view class="item" @click="toTopUp">{{ $t("me.Top Up") }}</uni-view>
              <uni-view class="item" @click="toWithdraw">{{ $t("me.Withdraw") }}</uni-view>
            </uni-view>
          </uni-view>
        </uni-view>
        <uni-view class="list">
          <uni-view class="item" @click="toIncome">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list3.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list3.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Income list") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="toTopUpRecord">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list4.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list4.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Top Up Record") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="toWithdrawRecord">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list5.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list5.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Withdrawal Record") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="toInvitation">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list6.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list6.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Invitation") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="toTeam">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list8.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list8.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Team report") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="toAccount">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list9.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list9.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Bank Account") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="changeLoginPassword">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list10.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list10.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Login password") }}</uni-view>
          </uni-view>
          <uni-view class="item" @click="changeTransactionPassword">
            <uni-image class="icon">
              <div
                style="
                  background-image: url('/static/me/list11.png');
                  background-position: 0% 0%;
                  background-size: 100% 100%;
                  background-repeat: no-repeat;
                "
              ></div>
              <img src="/static/me/list11.png" />
            </uni-image>
            <uni-view class="label">{{ $t("me.Transaction Password") }}</uni-view>
          </uni-view>
          <!-- 用来填充用的 -->
          <uni-view class="item"> </uni-view>
        </uni-view>
        <uni-view class="quitLogin" @click="signOut">{{ $t("me.sign out") }}</uni-view>
      </uni-view>
    </uni-page-body>
  </uni-page-wrapper>
</template>

<script>
import service from "@/store/service.js";

import uniPopup from "../../components/uni-popup/uni-popup";
import uniPopupDialog from "../../components/uni-popup-dialog/uni-popup-dialog";
export default {
  components: { uniPopup, uniPopupDialog },
  data() {
    return {
      popupTitle: "",
      popupPlaceholder: this.$t("me.Please enter a new password"),
      popup2Title: this.$t("me.Are you sure to change the password?"),
      username: "",
      level: "",
      balance: "",
      type: 0,
	  score: '',
      password: "",
    };
  },
  onShow() {
    service.auth(this, service.api.app_myuser, {}, function (self, res) {
      self.username = res.username;
      self.balance = res.money;
      self.level = res.vip;
      self.score = res.score;
    });
  },
  methods: {
    toTopUp() {
      uni.navigateTo({
        url: "/pages/topUp/top-Up",
      });
    },
    toWithdraw() {
      uni.navigateTo({
        url: "/pages/withDraw/withDraw",
      });
    },
    toIncome() {
      uni.navigateTo({
        url: "/pages/income/income",
      });
    },
    toTopUpRecord() {
      uni.navigateTo({
        url: "/pages/topUpRecord/topUpRecord",
      });
    },
    toWithdrawRecord() {
      uni.navigateTo({
        url: "/pages/withDrawalRecord/withDrawalRecord",
      });
    },
    toInvitation() {
      uni.navigateTo({
        url: "/pages/invitation/invitation",
      });
    },
    toTeam() {
      uni.navigateTo({
        url: "/pages/team/team",
      });
    },
    toAccount() {
      uni.navigateTo({
        url: "/pages/bank/bank",
      });
    },
    changeLoginPassword() {
      this.popupTitle = this.$t("me.Change Password");
      this.$refs.popup.open();
      this.type = 1;
    },
    changeTransactionPassword() {
      this.popupTitle = this.$t("me.Change transaction password");
      this.$refs.popup.open();
      this.type = 2;
    },
    close(done) {
      done();
    },

    confirm(done, value) {
      //二次确认
      this.$refs.popup2.open();
      this.password = value;
      done();
    },
    close2(done) {
      done();
    },
    confirm2(done, value) {
      //调用修改密码的接口/调用退出登录的接口
      done();
      if (this.popup2Title === this.$t("me.Are you sure you want to log out?")) {
        uni.removeStorageSync("token");
        uni.reLaunch({
          url: "/pages/login/login",
        });
      } else {
        if (this.type == 2) {
          service.auth(
            this,
            service.api.app_updatejypass,
            {
              newjypassword: this.password,
            },
            function (self, res) {}
          );
        } else {
          service.auth(
            this,
            service.api.app_updatepass,
            {
              newpassword: this.password,
            },
            function (self, res) {}
          );
        }
      }
    },
    signOut() {
      //开启确认
      this.popup2Title = this.$t("me.Are you sure you want to log out?");
      this.$refs.popup2.open();
    },
  },
};
</script>

<style>
@import url(./me.css);
</style>